package utils
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import flash.filters.GradientBevelFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
    public class TextUtil
    {
        public static var dropShadow:GlowFilter = new GlowFilter(0, 1, 2, 2, 10);

        public function TextUtil()
        {
            
        }

        public static function getInputTextField(param1:int = 30, param2:int = 18, param3:uint = 0, param4:String = "", param5:Boolean = true, param6:uint = 0, param7:Boolean = false, param8:uint = 16777215) : TextField
        {
            var text:TextField;
            var firstFocus:Boolean;
            var w:* = param1;
            var h:* = param2;
            var max:* = param3;
            var restrict:* = param4;
            var border:* = param5;
            var borderColor:* = param6;
            var isBg:* = param7;
            var bg:* = param8;
            text = new TextField();
            text.type = TextFieldType.INPUT;
            text.border = border;
            text.borderColor = borderColor;
            text.width = w;
            text.height = h;
            if (restrict != "")
            {
                text.restrict = restrict;
            }
            if (max > 0)
            {
                text.maxChars = max;
            }
            if (isBg)
            {
                text.background = true;
                text.backgroundColor = bg;
            }
            firstFocus;
            text.addEventListener(FocusEvent.FOCUS_IN, function (event:FocusEvent) : void
            {
                firstFocus = true;
                return;
            }
            );
            text.addEventListener(MouseEvent.CLICK, function (event:MouseEvent) : void
            {
                if (firstFocus)
                {
                    text.setSelection(0, text.length);
                    firstFocus = false;
                }
                return;
            }
            );
            text.addEventListener(MouseEvent.MOUSE_OVER, function (event:MouseEvent) : void
            {
                text.borderColor = 16711680;
                return;
            }
            );
            text.addEventListener(MouseEvent.MOUSE_OUT, function (event:MouseEvent) : void
            {
                text.borderColor = borderColor;
                return;
            }
            );
            return text;
        }

        public static function removeDeleteLine(param1:DisplayObject) : Shape
        {
            var _loc_2:Shape = null;
            if (param1.parent != null)
            {
                _loc_2 = param1.parent.getChildByName("line_for_" + param1.name) as Shape;
                if (_loc_2 != null)
                {
                    DisplayUtil.removeChild(_loc_2, param1.parent);
                }
            }
            return _loc_2;
        }

        public static function getGGTextField(param1:int = 18, param2:Boolean = false, param3:int = 3, param4:Boolean = false) : TextField
        {
            var _loc_5:* = new GradientBevelFilter(-3, 90, [16777215, 16777215, 14195240], [0, 0.26, 0.52], null, 5, 5, 10, BitmapFilterQuality.LOW);
            var _loc_6:* = new GlowFilter(0, 1, param3, param3, 20, BitmapFilterQuality.LOW);
            var _loc_7:* = new DropShadowFilter(0, 0, 0, 1, 2, 2, 2);
            return getFilterTextField([_loc_5, _loc_6, _loc_7], 16777215, param1, param2, param4);
        }

        public static function getGradientTextField(param1:String = "") : TextField
        {
            return getTextField(param1, 16777215, 18);
        }

        public static function getGlowTextField(param1:uint = 16777215, param2:uint = 0, param3:int = 18, param4:Boolean = false, param5:Boolean = false) : TextField
        {
            var _loc_6:* = new GlowFilter(param2, 1, 3, 3, 10, BitmapFilterQuality.LOW);
            return getFilterTextField([_loc_6], param1, param3, param4, param5);
        }

        public static function getNormalTextField(param1:uint, param2:int, param3:Boolean = false, param4:String = "left") : TextField
        {
            var _loc_5:* = new TextField();
            new TextField().selectable = false;
            var _loc_6:* = new TextFormat();
            new TextFormat().color = param1;
            _loc_6.size = param2;
            _loc_6.bold = param3;
            _loc_6.align = param4;
            _loc_5.defaultTextFormat = _loc_6;
            return _loc_5;
        }

        public static function getTextField(param1:String, param2:uint = 16777215, param3:int = 18, param4:Boolean = false, param5:Boolean = false, param6:Boolean = false, param7:String = "left", param8:Boolean = false, param9:int = 0, param10:Boolean = false, param11:Number = 0, param12:int = 1) : TextField
        {
            var _loc_15:DropShadowFilter = null;
            var _loc_13:* = new TextField();
            new TextField().tabEnabled = false;
            if (!param6)
            {
                _loc_13.autoSize = TextFieldAutoSize.LEFT;
            }
            _loc_13.multiline = true;
            _loc_13.maxChars = 255;
            _loc_13.selectable = param8;
            var _loc_14:* = new TextFormat();
            _loc_14.color = param2;
            _loc_14.size = param3;
            _loc_14.bold = param4;
            _loc_14.italic = param5;
            _loc_14.letterSpacing = param9;
            _loc_14.align = param7;
            _loc_13.defaultTextFormat = _loc_14;
            if (param1 != null)
            {
                _loc_13.htmlText = param1;
            }
            if (param10)
            {
                _loc_15 = new DropShadowFilter(0, 0, param11, 1, 4, 4, 5);
                _loc_13.filters = [_loc_15];
            }
            _loc_13.cacheAsBitmap = true;
            return _loc_13;
        }

        public static function addDeleteLine(param1:DisplayObject, param2:uint = 16777215) : Shape
        {
            var text:* = param1;
            var color:* = param2;
            if (text.parent == null)
            {
                return null;
            }
            var line:* = new Shape();
            var _loc_4:* = line.graphics;
            with (line.graphics)
            {
                lineStyle(1, color);
                moveTo(0, text.height * 0.5);
                lineTo(text.width, text.height * 0.5);
            }
            line.x = text.x;
            line.y = text.y;
            line.name = "line_for_" + text.name;
            text.parent.addChild(line);
            return line;
        }

        public static function getTextFieldEasy(param1:String, param2:uint = 0xffffff, param3:String = "", param4:String = "left", param5:int = 0, param6:int = 0, param7:int = 0, param8:Boolean = false) : TextField
        {
            var _loc_9:* = TextUtil.getTextField(param1, param2, 18, false, false, false, param4, false, 0, false);
            _loc_9.filters = [dropShadow];
            _loc_9.wordWrap = param8;
            _loc_9.name = param3;
            _loc_9.width = param7;
            _loc_9.x = param5;
            _loc_9.y = param6;
            return _loc_9;
        }

        public static function getFilterTextField(param1:Array, param2:uint, param3:int, param4:Boolean = false, param5:Boolean = false) : TextField
        {
            var _loc_6:* = new TextField();
            new TextField().filters = param1;
            _loc_6.selectable = false;
            _loc_6.multiline = param5;
            _loc_6.autoSize = TextFieldAutoSize.LEFT;
            var _loc_7:* = new TextFormat();
            new TextFormat().color = param2;
            _loc_7.size = param3;
            _loc_7.bold = param4;
            _loc_6.defaultTextFormat = _loc_7;
            return _loc_6;
        }
    }
}
